<?php

/**
 * bilan actions.
 *
 * @package    frigospeed
 * @subpackage bilan
 * @author     0
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class bilanActions extends sfActions
{
 /**
  * Executes index action
  *
  * @param sfRequest $request A request object
  */
  public function executeIndex(sfWebRequest $request)
  {
    //$this->forward('default', 'module');
		$this->commandes = Doctrine_Core::getTable('Commande');
		$this->commandes = Doctrine_Query::create()->select('c.id, sum(p.prix_achat * quantite) as pa, sum(a.prix_vente * quantite) as pv, (sum(a.prix_vente * quantite)-sum(p.prix_achat * quantite)) as ca')
			->from('commande c,article a,produit p')
			->where("c.id = a.commande_id")
			->andWhere("p.id = a.produit_id")
			->groupBy("c.id")
			->execute();
  }
	
	public function executeShow(sfWebRequest $request)
  {
			// get Doctrine_Connection object
		$con = Doctrine_Manager::getInstance()->connection();
		// execute SQL query, receive Doctrine_Connection_Statement
		$st = $con->execute("SELECT a.quantite AS quantite, p.description AS description, p.prix_achat AS achat, a.prix_vente AS vente, (a.prix_vente - p.prix_achat) AS ca FROM article a, produit p WHERE (p.id = a.produit_id AND a.commande_id = ".$request->getParameter('id').")");
		// fetch query result
		$this->produits = $st->fetchAll();
  }
}
